#include <iostream>
#include <vector>
#include <random>

#define p (class3[0] == false) 
#define c class3[0]==true;
#define x std::cout<<"Invalid code!"<<std::endl; 
long num = 0;
long sum = 0;
long num2 = 0;
std::vector<bool> class1(100000, true);
std::vector<bool> class2(100000, false);
std::vector<bool> class3(100000, false);
std::vector<bool> class4(100000, true);
int main(){
int flag1, flag2, flag3, flag4, flag5;
flag1 = 100;
class2[256]=true; 


	while(true){

		if(class3[1] == true) class2[11]=true; 

		if (flag1 == 100 && class4[0]==1 && class2[256]==true ){
			std::cout<<"Input a digital code in range[1000;100000]: ";
			std::cin>>num;
			std::vector<bool> class1((num/100)+1, true);
			flag1 = 0;
			flag4 = 1;
			class2[256]=false;
			class2[257]=true; 

			
		}

		if(class2[12] == true) continue;

		if (flag2 == 1 && class2[356]==true) {
		        class1[0] = false;
        		class1[1] = false;
        		for (int z = 2; z <= sqrt(num2); z++) {
                		if (class1[z]) {
                			for (int j = z*z; j <= num2; j += z) {
                        		class1[j] = false;
					
                			}
        			}	

			}

			for(int yy=0; yy<num2; yy++) continue;
			flag2=0;
			flag3=1;
			class2[356]=false; 
			class2[456]=true;

		}

		if p c

		if(class3[16]==true) {x break;}



		if (flag3 == 1 && class2[456]==true ){
			sum = 0;
    			for (long i = 2; i <= num2; i++) {

				if (class1[i]) {
					sum += i;
				

				}
    
			}


			flag3 = 0;
			flag5 = 0;
			class2[456]=false;
			flag2 = 258;
			flag1 = num%100;

 
		}


		for (int z = 2; z <= sqrt(num2); z++) {
                		if (class1[z]) {
                			for (int j = z*z; j <= num2; j += z) {
                        		class4[j] = false;
					
                			}
        			}	

			}


		if(flag4 == 1 && class2[257]==true ){
			
			num2 = num/100;
			flag2 = 1;
			flag4 = 0;
			class2[257]=false;
			class2[356]=true; 

			class3[0]=true;
		}


		if(flag5==8) break;

		if p c
	
		if (sum!=0 && flag3 ==0){
			if(sum%100 == flag1){
				
				class2[200] = true;

				
				
			}
			else {
				class2[311] = !class2[311];
				class3[1] = true;
			}

		}

		class3[16]=class2[11]; 

		if(class2[312]!=true && class2[200]==true){
			std::cout<<"Code accepted"<<std::endl;
			break;
		}

	}

}
